// HelloWorldController.java
package com.buytouch.mobile.client.buy.user;
 
import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
 
@Controller
@RequestMapping("/client")
public class ClientUserController {
	
	@Resource
	private ClientUserService clientUserService;
     
    @RequestMapping(value="/insert_user_join", method=RequestMethod.POST)
    public void get_test(@RequestParam Map<String, String> map, 
    								HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	
    	
    	/*
    	 * store_id은 강제 입력 0
    	 */
    	
    	map.put("store_id", "01043210030");
    	
    	/*
    	 * 
    	 */
    	clientUserService.insert_user_join(map);
    	/*
    	 * 흠... 이렇게 상대경로밖에 안되나.....
    	 * 알아보자
    	 * 
    	 */
    	response.sendRedirect("../../index.jsp");
    }
    
    @RequestMapping(value="/check_login")
    @ResponseBody
    public String check_login(@RequestParam Map<String, String> map
    												, HttpServletRequest request
    												, HttpServletResponse response){
    	Map result_map = clientUserService.check_login(map);
    	
    	if(result_map != null){
    		HttpSession session = request.getSession();
    		session.setAttribute("store_id", result_map.get("store_id"));
    		session.setAttribute("user_id", result_map.get("user_id"));
    		session.setAttribute("user_loc_gps_1", result_map.get("user_loc_gps_1"));
    		session.setAttribute("user_loc_gps_2", result_map.get("user_loc_gps_2"));
    		return "y";
    	}
    	
    	return "n";
    }
    
    //@RequestParam(value="id", required=false, defaultValue=1)
    @RequestMapping(value="/item_list")//, method=RequestMethod.POST)
    public ModelAndView item_check_request(@RequestParam(value="store_id", required=false) String store_id
    																					,HttpSession session) {
    	
    	/*
    	 * test
    	 */
    	//session.setAttribute("store_id", "01043210030");
    	/*
    	 * test
    	 */
    	
    	List cate_list = clientUserService.item_check_request_cate_nm((String)session.getAttribute("store_id"));
    	
    	ModelAndView mv = new ModelAndView("/mobile/client/item_list", "cate_list", cate_list);
    	
        return mv;
    }
    
    
    //@RequestParam(value="id", required=false, defaultValue=1)
    @RequestMapping(value="/item_list_detail")//, method=RequestMethod.POST)
    public ModelAndView item_check_request_item_list(@RequestParam(value="code_cate", required=true) String code_cate
    																					,HttpSession session) {
    	/*
    	 * test
    	 */
//    	session.setAttribute("store_id", "01043210030");
    	/*
    	 * test
    	 */
    	
    	List list = clientUserService.item_check_request_item_list((String)session.getAttribute("store_id"), code_cate);
    	
    	ModelAndView mv = new ModelAndView("/mobile/client/item_list_detail", "list", list);
    	
        return mv;
    }
    
//    @RequestMapping(value="/pay_item_list")//, method=RequestMethod.POST)
//    public ModelAndView pay_item_list(@RequestParam(value="item_list", required=true) String item_list
//    																					,HttpSession session) {
//    	/*
//    	 * test
//    	 */
////    	session.setAttribute("store_id", "01043210030");
//    	/*
//    	 * test
//    	 */
//    	
//	
//    	ModelAndView mv = new ModelAndView("/mobile/client/item_list_detail", "list", list);
//    	
//        return mv;
//    }
//    
    
}